/*H+lI6uny747rMye9nXjzTeLF3dh8vHk+0hn7bNZ/fZWxYT4MZkRBtcAGW6bLOJU2*/
import initButtonState from "../init/initButtonState";
import { PAGECODE, STATUS, FIELD, URL, DataSource } from '../../constance';

/**
 * 提交
 * @param {*} pageModel 
 */
export default function (pageModel) {
    const { multiLang: { getMultiLangData }, toast, ajax, spaCache } = pageModel;
    const multiLangData = getMultiLangData();
    const { updateCache } = spaCache;

    let pk_order = pageModel.get(PAGECODE.cardHead).getItemsValue(FIELD.pk).value;
    pk_order = (!pk_order || pk_order == 'undefined') ? pageModel.pageTo.getUrlParam(FIELD.id) : pk_order;
    let ts = pageModel.get(PAGECODE.cardHead).getItemsValue(FIELD.ts).value;
    let queryData = {
        pks: [pk_order],
        pkMapTs: { [pk_order]: ts },
        pagecode: PAGECODE.cardCode,
    };
    // 发送请求
    ajax({
        url: URL.commit,
        data: queryData,
        success: (res) => {
            if (res.data) {
                const data = res.data;
                const dataSource = DataSource;
                if (data) {
                    if (data.head) {
                        pageModel.get(PAGECODE.cardHead).setData({
                            formDataObj: { [PAGECODE.cardHead]: data.head[PAGECODE.cardHead] }
                        });
                    }
                    if (data.bodys && data.bodys[PAGECODE.cardbody1]) {
                        pageModel.get(PAGECODE.cardbody1).updateRows(data.bodys[PAGECODE.cardbody1]);
                    }
                    if (data.bodys && data.bodys[PAGECODE.cardbody2]) {
                        pageModel.get(PAGECODE.cardbody2).updateRows(data.bodys[PAGECODE.cardbody2]);
                    }
                }
                updateCache(pk_order, FIELD.pk, res.data, PAGECODE.cardHead, dataSource);//修改更新缓存
                pageModel.updatePageStatus(STATUS.browse);
                toast(multiLangData['4004POORDER-000037']);
                initButtonState(pageModel);
            }
        }
    });
}
/*H+lI6uny747rMye9nXjzTeLF3dh8vHk+0hn7bNZ/fZWxYT4MZkRBtcAGW6bLOJU2*/